package com.thread.reference;

import java.lang.ref.SoftReference;

/**
 * 软引用
 * 当内存够用不回收。不够用强制回收，适用于缓存
 */
public class SoftRefernce02 {
    public static void main(String[] args) {
        SoftReference<byte[]> m = new SoftReference<>(new byte[1024*1024*10]);
        System.out.println(m.get());

        System.gc();;
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(m.get());

        byte[] b = new byte[1024*1024*15];
        System.out.println(m.get());// vm options -Xmx30m -Xms30m
        // null 系统内存不够用

    }
}
